import type { IOnePost, IOnePostByTitle, IPostData, IPublicPost } from '@/types/posts'
import type { IdType, IPage } from '@/types/table'
import { request } from '@/utils/request'

/**
 * 获取文章列表
 * @param data 
 * @returns 
 */
export const getPostsList = (data: IPage) =>
    request<IPostData>('/posts/admin/all','get',data)

/**
 * 获取文章详情
 * @param id 
 * @returns 
 */
export const getOnePost =  (id:number) => 
    request<IOnePost>('/posts/'+id,'get')

/**
 * 删除文章
 * @param id 
 * @returns 
 */
export const delPost = (id:number) => 
    request<IdType>('/posts/'+id,'delete')

/**
 * 发布文章
 * @param data 
 * @returns 
 */
export const publicPost = (data:IPublicPost) => 
    request<string>('/posts/admin','post',data)

/**
 * 编辑文章
 * @param id 文章id 
 * @param data 更改/编辑 内容
 * @returns 
 */
export const updatedPost = (id:number,data:IPublicPost) => 
    request<string>('/posts/'+id,'patch',data)

/**
 * 根据标题模糊搜索
 * @param title 
 * @returns 
 */
export const searchByTitle = (title:string) =>
    request<IOnePostByTitle>('/posts/content?title='+title,'get')

/**
 * 获取文章审核列表
 * @param data 
 * @returns 
 */
export const proccessList = (data: IPage) =>
    request<IPostData>('/posts/passed/all','get',data)

/**
 * 审核文章违规
 * @param id 
 * @returns 
 */
export const notPassed = (id:number) => 
    request<string>('/posts/admin/'+id,'patch')

/**
 * 审核文章-通过
 * @param id 
 * @returns 
 */
export const isPassed = (id:number) => 
    request<string>('/posts/admin/passed/'+id,'patch')